<?php

class ParamPackTool {

    private $_novelid    = 0;
    private $_vcode      = 0;
    private $_updatetype = '';
    private $_updatedata = '';
    private $_chapterid  = 0;
    private $_s          = 0;
    private $_t          = 0;
    private $_type       = 0;
    private $_province   = '';
    private $_city       = '';
    private $_county     = '';
    private $_back       = '';
    private $_size       = 0;
    private $_style      = 0;
    private $_from      = 0;
    
    private static $_callback = '';
    private $_page            = 0;
    private $_pageSize        = 10;
    private $_orderBy         = 0;
    private $_isFinish        = 0;
    private $_wordCount       = 0;
    private $_needPay         = 0;
    private $_ctype           = 0;
    private $_kw              = '';
    private $_a          = '';
    
    private $_username        = '';
    private $_password        = '';
    private $_rePassword      = '';
    private $_newPassword      = '';
    private $_newRePassword      = '';
    private $_name            = '';
    private $_email           = '';
    private $_mobile          = '';
    private $_status          = 0;
    private $_ids             = array ();
    private $_id              = 0;
//    private $_type            = 0;
    private $_category        = 0;
    private $_uid             = 0;
    private $_sid             = 0;
    private $_mid             = 0;
    private $_stuid           = 0;
    private $_stuids          = 0;
    private $_nickname        = '';
    private $_age             = 0;
    private $_schoolage       = 0;
    private $_icon            = '';
    private $_company         = '';

    private $_opernid         = 0;
    private $_times           = 0;
    private $_number          = 0;
    private $_ask             = '';
    private $_homeworkid      = 0;
    private $_sectionid       = 0;
    private $_date            = '';

    private $_stime           = '';
    private $_etime           = '';
    private $_score           = 0;
    private $_star            = 1;
    private  $_imgCode        = '';
    private $_scene           = 1;





    /**
     * Parampack constructor.
     * @param array $arr
     */
    public function __construct ($arr = array ())
    {
        $this->_novelid          = isset ( $arr['novelid'] ) ? $arr['novelid'] : 0;          //小说id
        $this->_vcode            = isset ( $arr['vcode'] ) ? $arr['vcode'] : 0;              //验证码
        $this->_updatetype       = isset ( $arr['updatetype'] ) ? $arr['updatetype'] : '';   //修改字段
        $this->_updatedata       = isset ( $arr['updatedata'] ) ? $arr['updatedata'] : '';   //修改值
        $this->_chapterid        = isset ( $arr['chapterid'] ) ? $arr['chapterid'] : '';     //章节id
        $this->_s                = isset ( $arr['s'] ) ? $arr['s'] : '';
        $this->_t                = isset ( $arr['t'] ) ? $arr['t'] : '';
        $this->_type             = isset ( $arr['type'] ) ? $arr['type'] : '';               //书架类型
        $this->_province         = isset ( $arr['province'] ) ? $arr['province'] : '';       //省
        $this->_city             = isset ( $arr['city'] ) ? $arr['city'] : '';               //市
        $this->_county           = isset ( $arr['county'] ) ? $arr['county'] : '';           //区
        $this->_back             = isset ( $arr['back'] ) ? $arr['back'] : '';               //区
        $this->_size             = isset ( $arr['size'] ) ? $arr['size'] : 0;                //区
        $this->_style            = isset ( $arr['style'] ) ? $arr['style'] : 0;              //区
        $this->_from             = isset ( $arr['from'] ) ? $arr['from'] : 0;                //区
        
        self::$_callback         = isset ( $arr[ 'callback' ] ) ? $arr[ 'callback' ] : '';
        $this->_page             = isset ( $arr[ 'page' ] ) ? $arr[ 'page' ] : '';   //页码
        $this->_pageSize         = isset ( $arr[ 'pageSize' ] ) ? $arr[ 'pageSize' ] : '';   //页码
        $this->_orderBy          = isset ( $arr[ 'orderBy' ] ) ? $arr[ 'orderBy' ] : 0;      //排序
        $this->_isFinish         = isset ( $arr[ 'isFinish' ] ) ? $arr[ 'isFinish' ] : 999;  //0连载，1完本
        $this->_wordCount        = isset ( $arr[ 'wordCount' ] ) ? $arr[ 'wordCount' ] : 0;  //字数
        $this->_needPay          = isset ( $arr[ 'needPay' ] ) ? $arr[ 'needPay' ] : 999;    //0免费，1收费
        $this->_ctype            = isset ( $arr[ 'ctype' ] ) ? $arr[ 'ctype' ] : 0;          //0分类页，>0次级页
        $this->_kw               = isset ( $arr[ 'kw' ] ) ? $arr[ 'kw' ] : '';               //关键词
        $this->_a                = isset ( $arr['a'] ) ? $arr['a'] : '';

        $this->_username         = isset ( $arr[ 'username' ] ) ? $arr[ 'username' ] : '';
        $this->_password         = isset ( $arr[ 'password' ] ) ? $arr[ 'password' ] : '';
        $this->_rePassword       = isset ( $arr[ 'rePassword' ] ) ? $arr[ 'rePassword' ] : '';
        $this->_newPassword       = isset ( $arr[ 'newPassword' ] ) ? $arr[ 'newPassword' ] : '';
        $this->_newRePassword       = isset ( $arr[ 'newRePassword' ] ) ? $arr[ 'newRePassword' ] : '';
        $this->_name             = isset ( $arr[ 'name' ] ) ? $arr[ 'name' ] : '';
        $this->_email            = isset ( $arr[ 'email' ] ) ? $arr[ 'email' ] : '';
        $this->_mobile           = isset ( $arr[ 'mobile' ] ) ? $arr[ 'mobile' ] : '';  //手机号
        $this->_status           = isset ( $arr[ 'status' ] ) ? $arr[ 'status' ] : '';
        $this->_ids              = isset ( $arr[ 'ids' ] ) ? $arr[ 'ids' ] : array ();
        $this->_id               = isset ( $arr[ 'id' ] ) ? $arr[ 'id' ] : 0;
        $this->_type             = isset ( $arr[ 'type' ] ) ? $arr[ 'type' ] : 0;
        $this->_category         = isset ( $arr[ 'category' ] ) ? $arr[ 'category' ] : 0;
        $this->_imgCode         = isset ( $arr[ 'imgCode' ] ) ? $arr[ 'imgCode' ] : '';
         $this->_scene        = isset ( $arr[ 'scene' ] ) ? $arr[ 'scene' ] : 1;

        $this->_uid              = isset ( $arr[ 'uid' ] ) ? $arr[ 'uid' ] : 0;
        $this->_sid              = isset ( $arr[ 'sid' ] ) ? $arr[ 'sid' ] : 0;
        $this->_mid              = isset ( $arr[ 'mid' ] ) ? $arr[ 'mid' ] : 0;
        $this->_stuid            = isset ( $arr[ 'stuid' ] ) ? $arr[ 'stuid' ] : 0;
        $this->_stuids           = isset ( $arr[ 'stuids' ] ) ? $arr[ 'stuids' ] : 0;
        $this->_nickname         = isset ( $arr[ 'nickname' ] ) ? $arr[ 'nickname' ] : 0;
        $this->_age              = isset ( $arr[ 'age' ] ) ? $arr[ 'age' ] : 0;
        $this->_schoolage        = isset ( $arr[ 'schoolage' ] ) ? $arr[ 'schoolage' ] : 0;
        $this->_icon             = isset ( $arr[ 'icon' ] ) ? $arr[ 'icon' ] : '';
        $this->_company          = isset ( $arr[ 'company' ] ) ? $arr[ 'company' ] : '';

        $this->_opernid          = isset ( $arr[ 'opernid' ] ) ? $arr[ 'opernid' ] : 0;
        $this->_times            = isset ( $arr[ 'times' ] ) ? $arr[ 'times' ] : 0;
        $this->_number           = isset ( $arr[ 'number' ] ) ? $arr[ 'number' ] : 0;
        $this->_ask              = isset ( $arr[ 'ask' ] ) ? $arr[ 'ask' ] : '';
        $this->_oid              = isset ( $arr[ 'oid' ] ) ? $arr[ 'oid' ] : '';
        $this->_homeworkid       = isset ( $arr[ 'homeworkid' ] ) ? $arr[ 'homeworkid' ] : 0;
        $this->_sectionid        = isset ( $arr[ 'sectionid' ] ) ? $arr[ 'sectionid' ] : 0;
        $this->_date             = isset ( $arr[ 'date' ] ) ? $arr[ 'date' ] : '';

        $this->_stime            = isset ( $arr[ 'stime' ] ) ? $arr[ 'stime' ] : '';
        $this->_etime            = isset ( $arr[ 'etime' ] ) ? $arr[ 'etime' ] : '';
        $this->_score            = isset ( $arr[ 'score' ] ) ? $arr[ 'score' ] : 0;
        $this->_star             = isset ( $arr[ 'star' ] ) ? $arr[ 'star' ] : 0;
        $this->_star             = isset ( $arr[ 'imgCode' ] ) ? $arr[ 'imgCode' ] : '';

    }
    
    public function getFrom()
    {
        $from = $this->_from;
        if ( ! trim($from) )
        {
            return '';
        }
        return strip_tags($from);
    }
    
    public function getA()
    {
        $a = $this->_a;
        if ( ! trim($a) )
        {
            return '';
        }
        return strip_tags($a);
    }
    
    public function getT()
    {
        $t = $this->_t;
        if ( ! trim($t) )
        {
            return '';
        }
        return strip_tags($t);
    }
    
    //获取关键词
    public function getKeyword()
    {
        $kw = $this->_kw;
        if ( ! trim($kw) )
        {
            return '';
        }
        return strip_tags($kw);
    }
    
    //获取分类
    public function getCtype()
    {
        $ctype = $this->_ctype;
        if ( ! $ctype )
        {
            return 0;
        }
        return intval($ctype);
    }
    
    //获取背景色
    public function getBack()
    {
        $back = $this->_back;
        if ( !isset($back) )
        {
            return '';
        }
        return $back;
    }
    
    //获取字体大小
    public function getSize()
    {
        $size = $this->_size;
        if ( ! $size )
        {
            return 0;
        }
        return $size;
    }
    
    //获取观看方式
    public function getStyle()
    {
        $style = $this->_style;
        if ( ! $style )
        {
            return 0;
        }
        return $style;
    }
    
    //获取章节id
    public function getChapterId($must = TRUE)
    {
        $chapterid = $this->_chapterid;
        if ( $must && ! $chapterid )
        {
            throw new YExceptionTool ( YExceptionTool::NOVELID_ERROR );
        }
        return $chapterid;
    }
    
    //获取session
    public function getSession($must = TRUE){
        $s = $this->_s;
        if ( $must && ! $s )
        {
            throw new YExceptionTool ( YExceptionTool::NOVELID_ERROR );
        }
        return $s;
    }
    
    //获取小说id
    public function getNovelId ($must = TRUE)
    {
        $novelid = $this->_novelid;
        if ( $must && ! $novelid )
        {
            throw new YExceptionTool ( YExceptionTool::NOVELID_ERROR );
        }
        return $novelid;
    }
    
    //获取验证码
    public function getVcode ($must = TRUE)
    {
        $vcode = $this->_vcode;
        if ( $must && ! $vcode )
        {
            throw new YExceptionTool ( YExceptionTool::VCODE_ERROR );
        }
        return $vcode;
    }
    
    //获取用户ip
    public function getUserIp () 
    {
        $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
        if (!$ip) {
            $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
        }

        $a = explode('|', str_replace(',', '|', $ip));
        return trim($a[0]);
    }
    
    //获取修改字段
    public function getUpdateType ( $must = TRUE )
    {
        $updateType = $this->_updatetype;
        if ( $must && ! trim($updateType) )
        {
            throw new YExceptionTool ( YExceptionTool::UPDATE_TYPE_ERROR );
        }
        return $updateType;
    }
    
    //获取省
    public function getProvince( $must = TRUE )
    {
        $province = $this->_province;
        if ( $must && ! trim($province) )
        {
            return '';
        }
        return $province;
    }
    
    //获取市
    public function getCity( $must = TRUE )
    {
        $city = $this->_city;
        if ( $must && ! trim($city) )
        {
            return '';
        }
        return $city;
    }
    
    //获取区
    public function getCounty( $must = TRUE )
    {
        $county = $this->_county;
        if ( $must && ! trim($county) )
        {
            return '';
        }
        return $county;
    }
    
    //获取修改字段内容
    public function getUpdateData ( $must = TRUE )
    {
        $updateData = $this->_updatedata;
        if ( $must && ! trim($updateData) )
        {
            throw new YExceptionTool ( YExceptionTool::UPDATE_DATA_ERROR );
        }
        return $updateData;
    }
    
    //获取用户ID
    public function getUserId ($must = TRUE)
    {
        $uid = $this->_uid;
        if ( $must && ! $uid )
        {
            return false;
        }
        return $uid;
    }
    
    //获取类型type
    public function getType($must = TRUE)
    {
        $type = $this->_type;
        if ( $must && ! $type )
        {
            return 1;
        }
        return $type;
    }

    public static function getCallback ()
    {
        return self::$_callback;
    }

    public function getPage ()
    {
        return intval ( $this->_page );
    }
    
    public function getPageSize ()
    {
        return intval ( $this->_pageSize );
    }
    
    //获取排序
    public function getOrderBy()
    {
        return intval ( $this->_orderBy );
    }
    
    //获取状态
    public function getIsFinish()
    {
        return intval ( $this->_isFinish );
    }
    
    //字数
    public function getWordCount()
    {
        return intval ( $this->_wordCount );
    }
    
    //收费免费
    public function getNeedPay()
    {
        return intval ( $this->_needPay );
    }

    public function getUserName ($must = TRUE)
    {
        $username = trim ( strip_tags ( $this->_username ) );
        if ( $must && '' == $username )
        {
            echo json_encode([ 'status' => 1,'msg' => YExceptionTool::getMsg(YExceptionTool::USERNAME_ERROR)]);
            exit();
        }
        return $username;
    }

    public function getPassword ($must = TRUE)
    {
        $password = trim ( strip_tags ( $this->_password ) );
        if ( $must && '' == $password )
        {
            echo json_encode([ 'status' => 1,'msg' => YExceptionTool::getMsg(YExceptionTool::PASSWORD_ERROR)]);
            exit();
        }
        return $password;
    }
    
    public function getRepassword($must = TRUE){
        $rePassword = trim(strip_tags($this->_rePassword));
        if( $must && $rePassword == ''){
            echo json_encode([ 'status' => 12009,'msg' => YExceptionTool::getMsg(YExceptionTool::REPASSWORD_ERROR)]);
            exit();
        }
        return $rePassword;
    }
    
    public function getNewRepassword($must = TRUE){
        $newPassword = trim(strip_tags($this->_newPassword));
        return $newPassword;
    }
    
    public function getNewReRepassword($must = TRUE){
        $newRepassword = trim(strip_tags($this->_newRePassword));
        return $newRepassword;
    }

    public function getName ($must = TRUE)
    {
        $name = trim ( strip_tags ( $this->_name ) );
        if ( $must && '' == $name )
        {
            throw new YExceptionTool ( YExceptionTool::NAME_ERROR );
        }
        return $name;
    }

    public function getEmail ($must = TRUE)
    {
        $email = trim ( strip_tags ( $this->_email ) );
        if ( $must && '' == $email )
        {
            throw new YExceptionTool ( YExceptionTool::EMAIL_ERROR );
        }
        if ( '' != $email )
        {
            $emailReg = '/^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/';
            if ( ! preg_match ( $emailReg , $email ) )
            {
                return YExceptionTool::EMAIL_ERROR;
//                throw new YExceptionTool ( YExceptionTool::EMAIL_ERROR );
            }
        }
        return $email;
    }

    public function getMobile ($must = TRUE)
    {
        $mobile = trim ( strip_tags ( $this->_mobile ) );
        if ( $must && '' == $mobile )
        {
            echo json_encode([ 'status' => 11009,'msg' => YExceptionTool::getMsg(YExceptionTool::MOBILE_ERROR)]);
            exit();
        }
        if ( '' != $mobile )
        {
//            $mobileReg = '/1[3|4|5|7|8]\d{9}$/';
            if ( ! preg_match("/^((\(\d{2,3}\))|(\d{3}\-))?1[3,4,5,7,8]\d{9}$/", $mobile) )
            {
                echo json_encode([ 'status' => 11009,'msg' => YExceptionTool::getMsg(YExceptionTool::MOBILE_ERROR)]);
                exit();
            }
        }
        return $mobile;
    }
    
    public function getImgCode ($must = TRUE)
    {
        $imgCode = trim ( strip_tags ( $this->_imgCode ) );
        return $imgCode;
    }
    public function getScene ($must = TRUE){
        $scene = trim ( strip_tags ( $this->_scene ) );
        return $scene;
    }

    public function getUid ($must = TRUE)
    {
        $uid = $this->_uid;
        if ( $must && ! $uid )
        {
            throw new YExceptionTool ( YExceptionTool::UID_ERROR );
        }
        return $uid;
    }

    public function getId ($must = TRUE)
    {
        $id = $this->_id;
        if ( $must && ! $id )
        {
            throw new YExceptionTool ( YExceptionTool::ID_ERROR );
        }
        return $id;
    }

    public function getSid ($must = TRUE)
    {
        $sid = $this->_sid;
        if ( $must && ! $sid )
        {
            throw new YExceptionTool ( YExceptionTool::SID_ERROR );
        }
        return $sid;
    }

    public function getMid ($must = TRUE)
    {
        $mid = $this->_mid;
        if ( $must && ! $mid )
        {
            throw new YExceptionTool ( YExceptionTool::MID_ERROR );
        }
        return $mid;
    }

    public function getCatgory ($must = TRUE)
    {
        $category = $this->_category;
        if ( $must && ! $category )
        {
            throw new YExceptionTool ( YExceptionTool::CATEGORY_ERROR );
        }
        return $category;
    }

//    public function getType ($must = TRUE)
//    {
//        $type = $this->_type;
//        if ( $must && ! $type )
//        {
//            throw new YExceptionTool ( YExceptionTool::TYPE_ERROR );
//        }
//        return $type;
//    }

    public function getOid ($must = TRUE)
    {
        $oid = $this->_oid;
        if ( $must && ! $oid )
        {
            throw new YExceptionTool ( YExceptionTool::OID_ERROR );
        }
        return $oid;
    }

    public function getStuid ($must = TRUE)
    {
        $stuid = $this->_stuid;
        if ( $must && ! $stuid )
        {
            throw new YExceptionTool ( YExceptionTool::STUID_ERROR );
        }
        return $stuid;
    }

    public function getStuids ($must = TRUE)
    {
        $stuids = $this->_stuids;
        if ( $must && ! $stuids )
        {
            throw new YExceptionTool ( YExceptionTool::STUID_ERROR );
        }
        return $stuids;
    }

    public function getNickname ($must = TRUE)
    {
        $nickname = $this->_nickname;
        if ( $must && '' == $nickname )
        {
            throw new YExceptionTool ( YExceptionTool::NICKNAME_ERROR );
        }
        return $nickname;
    }

    public function getCompany ($must = TRUE)
    {
        $company = $this->_company;
        if ( $must && '' == $company )
        {
            throw new YExceptionTool ( YExceptionTool::COMPANY_ERROR );
        }
        return $company;
    }

    public function getAge ($must = TRUE)
    {
        $age = $this->_age;
        if ( $must && 0 == $age )
        {
            throw new YExceptionTool ( YExceptionTool::AGE_ERROR );
        }
        return $age;
    }

    public function getSchoolage ($must = TRUE)
    {
        $schoolage = $this->_schoolage;
        if ( $must && 0 == $schoolage )
        {
            throw new YExceptionTool ( YExceptionTool::SCHOOLAGE_ERROR );
        }
        return $schoolage;
    }

    public function getIcon ($must = TRUE)
    {
        $icon = $this->_icon;
        if ( $must && '' == $icon )
        {
            throw new YExceptionTool ( YExceptionTool::ICON_ERROR );
        }
        return $icon;
    }

    public function getOpernid($must = TRUE)
    {
        $opernid = $this->_opernid;
        if ($must && 0 == $opernid)
        {
            throw new YExceptionTool ( YExceptionTool::OPERNID_ERROR );
        }
        return $opernid;
    }

    public function getTimes($must = TRUE)
    {
        $times = $this->_times;
        if ($must && 0 == $times)
        {
            throw new YExceptionTool ( YExceptionTool::TIMES_ERROR );
        }
        return $times;
    }

    public function getNumber($must = TRUE)
    {
        $number = intval($this->_number);
        if ($must && 0 == $number)
        {
            throw new YExceptionTool ( YExceptionTool::NUMBER_ERROR );
        }
        return $number;
    }

    public function getAsk($must = TRUE)
    {
        $ask = strip_tags($this->_ask);
        if ($must && '' == $ask)
        {
            throw new YExceptionTool ( YExceptionTool::ASK_ERROR );
        }
        return $ask;
    }

    public function getHomeworkid($must = TRUE)
    {
        $homeworkid = intval($this->_homeworkid);
        if ($must && 0 == $homeworkid)
        {
            throw new YExceptionTool ( YExceptionTool::HOMEWORKID_ERROR );
        }
        return $homeworkid;
    }

    public function getScore($must = TRUE)
    {
        $score = $this->_score;
        if ($must && 0 == $score)
        {
            throw new YExceptionTool ( YExceptionTool::SCORE_ERROR );
        }
        return $score;
    }

    public function getSectionid($must = TRUE)
    {
        $sectionid = $this->_sectionid;
        if ($must && 0 == $sectionid)
        {
            throw new YExceptionTool ( YExceptionTool::SECTIONID_ERROR );
        }
        return $sectionid;
    }

    public function getDate($must = TRUE)
    {
        $date = $this->_date;
        if ($must && '' == $date)
        {
            throw new YExceptionTool ( YExceptionTool::DATE_ERROR );
        }
        return $date;
    }

    public function getStime($must = TRUE)
    {
        $stime = $this->_stime;
        if ($must && '' == $stime)
        {
            throw new YExceptionTool ( YExceptionTool::STIME_ERROR );
        }
        return $stime;
    }

    public function getEtime($must = TRUE)
    {
        $etime = $this->_etime;
        if ($must && '' == $etime)
        {
            throw new YExceptionTool ( YExceptionTool::ETIME_ERROR );
        }
        return $etime;
    }

    public function getStar($must = TRUE)
    {
        $star = intval($this->_star);
        if ($must && 0 == $star)
        {
            throw new YExceptionTool ( YExceptionTool::STAR_ERROR );
        }
        return $star;
    }
}
